package com.szlanyou.tcp_server_demo.adapter;

import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

import com.camnter.easyrecyclerview.holder.EasyRecyclerViewHolder;
import com.szlanyou.protocol_service.LogUtil;
import com.szlanyou.tcp_server_demo.R;
import com.szlanyou.tcp_server_demo.expandableview.CollapseView;

import java.util.Random;

/**
 * @author 陈章
 * create at 2021/1/20 15:46
 * desc:
 */
public class ClientAdapter extends BaseEasyRecyclerViewAdapter<ClientItemModel> {


    @Override
    protected int getLayoutId() {
        return R.layout.adapter_client_list;
    }

    @Override
    protected void bindData(final ClientItemModel data, final int position, final EasyRecyclerViewHolder viewHolder) {
        CollapseView collapseView = viewHolder.findViewById(R.id.collapseView);
        collapseView.setNumber(String.valueOf(position + 1));
        collapseView.setTitle(data.tcpClient.getAddress());
        collapseView.setContent(R.layout.view_expand);
        collapseView.setEnableCollapse(data.isActivated());

        View tvNumber = viewHolder.findViewById(R.id.numberTextView);
        tvNumber.setBackgroundResource(data.isActivated() ? android.R.color.holo_green_light : android.R.color.darker_gray);

        TextView tvRecMsg = viewHolder.findViewById(R.id.tv_rec_msg);
        tvRecMsg.setText(data.cmdSb.toString());

        data.setOnViewChangedListener(new ClientItemModel.OnViewChangedListener() {
            @Override
            public void onViewChanged() {
                notifyItemChangedOnUiThread(position);
            }
        });

        viewHolder.findViewById(R.id.btn_send_msg).setOnClickListener(data.sendMsgClickListener);

        viewHolder.findViewById(R.id.btn_pressure_test).setOnClickListener(data.pressureTestClickListener);

        viewHolder.findViewById(R.id.btn_clear_log).setOnClickListener(data.clearLogClickListener);
    }
}
